package com.snailct.bpp.client.component.base.service.impl;

import com.snailct.bpp.client.component.base.dao.UserDao;
import com.snailct.bpp.client.component.base.model.User;
import com.snailct.bpp.client.component.base.service.IUserService;
import com.snailct.bpp.service.core.commons.DefaultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by huangxa on 2016/6/2.
 */
@Service
public class UserService extends DefaultService implements IUserService {
    @Autowired
    private UserDao userDao;
    public List<User> findAllUser() {
        List<User> result = userDao.queryByQry();
        return result;
    }

    public void addUser(User user){
        System.out.println("调用addUser"+user.getUsername());
        user.setStatus(User.UserStatus.ACTIVATED);
        userDao.insert(user);
    }
    private void delUserById(Integer id){
        User user  = new User();
        user.setId(id);
        userDao.delete(user);
    }

    public void delUser(Integer id) {
        delUserById(id);
    }

    public User getUserById(Integer id) {
        User user  = new User();
        user.setId(id);
        return userDao.getById(user);
    }

    public void updateUser(User user) {
        userDao.update(user);
    }
}
